#include "comm.hpp"


int main()
{
    key_t k = ftok(PATH_NAME, PROJ_ID);
    if(k<0)
    {
        Log("creat key failed", Error)<<" client key : "<< k <<endl;
        exit(-1);
    }

    Log("creat key done", Debug)<<" client key : "<< k <<endl;

    //获取共享内存
    int shmid = shmget(k, SHM_SIZE, 0);
    if(shmid < 0)
    {
        Log("create shm failed", Error) <<" client key : "<< k <<endl;
        exit(2);
    }
    Log(" create shm success", Debug) <<" client key : " << k <<endl;

    sleep(10);


    char* shmaddr = (char *)shmat(shmid, nullptr, 0);
    if(shmaddr == nullptr)
    {
        Log(" attach shm failed", Error) <<" client key : "<< k<<endl;
        exit(3);
    }
    Log(" attach shm success", Debug) <<" client key : "<< k<<endl;
    sleep(10);


    // 使用

    //去关联
    int n = shmdt(shmaddr);
    assert(n!=-1);
    Log("detach shm success", Debug) << "client key : "<< k <<endl;

    sleep(10);


    // client 要不要chmctl删除呢？不需要
    return 0;
}